# build library
SET(COM_SRC ffmpeg_decode.c rtp_pack.c network.c)

IF (WIN32)
  SET(COM_SRC vfw_capture.c ${COM_SRC})
ELSE ()
  SET(COM_SRC v4l_capture.c ${COM_SRC})
ENDIF ()

IF (PLAT STREQUAL "RPI")        ## raspberry pi
  SET (CK_SRC soft_convert.c omx_encode.c ${COM_SRC})
  INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/third-party/ilclient)   # ilclient headers
  AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/third-party/ilclient/ ILCLIENT_SRC) # include ilclient sources
  SET (CK_SRC ${CK_SRC} ${ILCLIENT_SRC})
ELSEIF (PLAT STREQUAL "FSL")        ## freescale
  SET(CK_SRC ipu_convert.c vpu_encode.c ${COM_SRC})
ELSEIF (PLAT STREQUAL "PC")      ## PC
  SET(CK_SRC ffmpeg_convert.c ffmpeg_encode.c ${COM_SRC})
ENDIF (PLAT STREQUAL "RPI")

ADD_LIBRARY(${CK_NAME} SHARED ${CK_SRC})
TARGET_LINK_LIBRARIES(${CK_NAME} ${LIBS})
IF (PLAT STREQUAL "RPI")    # additional macros
    SET_TARGET_PROPERTIES(${CK_NAME} PROPERTIES COMPILE_FLAGS "-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM ")
ENDIF ()

# install header files
SET(INCLUDEDIR  ${CMAKE_INSTALL_PREFIX}/include/)
INSTALL(FILES ${CK_IDX_HDR} DESTINATION ${INCLUDEDIR})
SET(INCLUDE_CK_DIR  ${CMAKE_INSTALL_PREFIX}/include/camkit)
INSTALL(FILES ${CK_HDRS} DESTINATION ${INCLUDE_CK_DIR})

# install library
SET(LIB_PREFIX ${CMAKE_INSTALL_PREFIX}/lib)
INSTALL(
	TARGETS ${CK_NAME} 
	ARCHIVE DESTINATION ${LIB_PREFIX}	#fix "install Library TARGETS given no DESTINATION!" error
	LIBRARY DESTINATION ${LIB_PREFIX}
	)
